<template>
	<view class="contents">
		<view>
			<h3>请输入新的手机号</h3>
			<text style="font-size: 24upx;color: #999;padding-top: 24upx;display: inline-block;">换绑手机号之后，可以用新的手机号及当前密码登录</text>
		</view>
		<u-input class="input" v-model="phone" placeholder="请输入新手机号" maxlength="11" :border="true"
			border-color="#eee" background-color="#F5F5F5" style="margin-top: 50upx;"/>
		<view class="u-flex u-row-between u-col-center">
			<u-input class="input" v-model="code" placeholder="请输入验证码" maxlength="6" :border="true"
				border-color="#eee" />
			<text class="sendcoder" @click="editPwdSms">{{clickText}}</text>
		</view>
		<u-button type="error" mode="plain" style="margin-top: 40upx;" @click="confirmClick">确定</u-button>
	</view>
</template>

<script>
	let courr = 60;
	let setId = null;
	export default {
	
		data() {
			return {
				phone: "",
				newpwd: "",
				newpwd2: "",
				code: "",
				clickText: ""
			};
		},
		onLoad() {
			this.gethuoquphone();
			uni.setNavigationBarTitle({
				title: '绑定手机号'
			});
			this.clickText = '获取验证码'
		},
		copmputed: {
			returnPwd() {
				return this.newpwd === this.newpwd2
			}
		},
	
		methods: {
			confirmClick() {
	// 			if (this.code == "") {
	// 				this.$toast('请输入验证码');
	// 				return false;
	// 			}
	// 			if (this.newpwd == "") {
	// 				this.$toast('请输入密码');
	// 				return false;
	// 			}
	// 			if (this.newpwd !== this.newpwd2) {
	// 				return this.$toast('两次输入的密码不一致');
	
	// 			}
	
				this.$http.geteditphone({
					phone: this.phone,
					phonecode: this.code,
					// password:this.newpwd,
					// repwd:this.newpwd2,
				}).then(res => {
					if (res.status == 200) {
						uni.showToast({
							title: res.mess	
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1200)
						console.log(res)
					} else {
						uni.showToast({
							title: res.mess,
							icon: 'none'
						})
					}
				});
			},
			editPwdSms() {
				if (this.phone.length != 11) {
					this.$toast('请输入正确的手机号');
					return false;
				}
				if (setId) {
					// 禁止重复发送
					return false;
				}
				this.$http.getsendcodeWx({
					phone: this.phone
				}).then(res => {
					if (res.status == 200) {
						uni.showToast({
							title:res.mess
						})
						setId = setInterval(() => {
							courr--;
							if (courr == 0) {
								courr = 60;
								clearInterval(setId);
								this.clickText = '重新获取';
	
								return false;
							}
							this.clickText = courr + "s";
						}, 1000);
					}else{
						uni.showToast({
							title:res.mess,
							icon:'none'
						})
					}
				});
			},
			gethuoquphone() {
				this.$http.gethuoquphone().then(res => {
					if (res.status == 200) {
						this.phone = res.data.phone;
						
					}else{
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	uni-page-body{
		background-color: #fff;
	}
	.inputWrap {
	
		background-color: #fff;
		padding: 30upx;
	}
	
	.input {
		height: 80upx;
		margin: 10upx 0;
		background-color: #F5F5F5;
		padding-top: 50upx;
	}
	
	.sendcoder {
		font-size: 24upx;
		color: #FF3D3D;
		margin-left: 20upx;
	}
	.contents{
		padding: 30upx 50upx;
	}
</style>
